﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Tesis2.Models;

namespace Tesis2.DAL
{
    public class UnitOfWork : IDisposable
    {
        private TesisDBContext context = new TesisDBContext();
        private GenericRepository<Almacen> almacenRepository;
        private GenericRepository<Dano> danoRepository;

        public GenericRepository<Almacen> DepartmentRepository
        {
            get
            {

                if (this.almacenRepository == null)
                {
                    this.almacenRepository = new GenericRepository<Almacen>(context);
                }
                return almacenRepository;
            }
        }

        public GenericRepository<Dano> CourseRepository
        {
            get
            {

                if (this.danoRepository == null)
                {
                    this.danoRepository = new GenericRepository<Dano>(context);
                }
                return danoRepository;
            }
        }

        public void Save()
        {
            context.SaveChanges();
        }

        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}